/*
 * File:   ChessBoard.h
 * Author: crash
 *
 * Created on February 28, 2011, 7:53 PM
 */

#ifndef CHESSBOARD_H
#define	CHESSBOARD_H

#include "IBoardListener.h"
#include <Typesfwd.h>
#include "pieces/ChessPiece.h"
#include <boost/unordered_map.hpp>
#include <set>

namespace model
{
	class ChessBoard
	{
		typedef boost::unordered_map<const Location, myTypes::cPiece> boardMap;
		typedef std::set<const IBoardListener*> listenerSet;
		boardMap grid;
		listenerSet listeners;
		bool lightTurn;

		void copy(const ChessBoard&);
	public:
		static const int SIZE = 8;
		ChessBoard();
		ChessBoard(const ChessBoard&);
		ChessBoard& operator =(const ChessBoard&);

		void addBoardListener(const IBoardListener&);

		void removeBoardListener(const IBoardListener&);

		bool setPiece(const Location&, const myTypes::cPiece&);

		myTypes::cPiece removePieceAt(const Location&);

		const myTypes::cPiece& getPieceAt(const Location&) const;

		bool hasLocation(const Location&) const;

		void reset();

		void switchTurn();

		bool isLightTurn() const;

	protected:
		void fireBoardChangeEvent(const Location&, const myTypes::cPiece&);
	};
} // namespace model

#endif	/* CHESSBOARD_H */

